
<?php 
	include_once("web_header.php");
?>

<div class="web_wrap">
    <div class="reg_content_wrap">
         <h4>注册训练日教练</h4>

         <div style="width:500px; margin:auto;margin-top:40px;">

				<form class="form-horizontal" role="form">
				   <div class="form-group">
				      <label for="firstname" class="col-sm-2 control-label">手机号</label>
				      <div class="col-sm-10">
				         <input type="text" class="form-control" id="phonenumber" 
				            placeholder="请输入正确的手机号" style="display:inline-block;width:70%">
							<span class="btn gain_code">获取验证码</span>
				      </div>
				   </div>

				   <div class="form-group">
				      <label for="firstname" class="col-sm-2 control-label">验证码</label>
				      <div class="col-sm-10">
				         <input type="text" class="form-control" id="checkcode" 
				            placeholder="请输入收到的验证码">
				      </div>
				   </div>


				   <div class="form-group">
				      <label for="lastname" class="col-sm-2 control-label">姓名</label>
				      <div class="col-sm-10">
				         <input type="text" class="form-control" id="realname" 
				            placeholder="请输入真实姓名">
				      </div>
				   </div>


				   <div class="form-group">
				      <label for="lastname" class="col-sm-2 control-label">设置密码</label>
				      <div class="col-sm-10">
				         <input type="password" class="form-control" id="password" 
				            placeholder="请设置训练日登录密码">
				      </div>
				   </div>
 


				   <div class="form-group">
				      <div class="col-sm-offset-2 col-sm-10">
				           <button type="button" id="regbtn" class="btn btn-primary">下一步</button>
 				           <button type="button" id="loginbtn" style="float:right" class="btn btn-link">已注册请登录</button>
				      </div>
				   </div>
				</form>

         </div>

    </div>
</div>


<script type="text/javascript">

			var wait=60;
		    function time(o) {
		        if (wait == 0) {
		        	$(o).removeClass('un');  
		            $(o).text("重新获取");
		            wait = 60;
		            $('.yy_tit').show();
		            $('.code_box').css("margin-top",0);
		        }else if(wait == 30){
		        	//$('.yy_tit').show();
		            //$('.code_box').css("margin-top",0);
		            $(o).text(wait+"秒");
		            wait--;
		            setTimeout(function() {
		                time(o)
		            },
		            1000);
		        } else {
		        	$(o).addClass('un');
		            $(o).text(wait+"秒");
		            wait--;
		            setTimeout(function() {
		                time(o)
		            },
		            1000);
		        }
		    }

			$('document').ready(function(){

				//查看协议
				$('.ty_tit .plxy').click(function(){
					//$.load_page({url:"http://peilian.test.58v5.cn/more/protocol",title:"陪练协议"});
				});
				
				//发送验证码
				$('.gain_code').bind('click',function(){
					var type = $(this).attr('type');
 					if ((type != "call" && wait == 60) || type == "call") {

						var phone = $('#phonenumber').val();

						if(phone==''){
		                      layer.open({
								    content: '请填写完整',
								    className: 'bluelayer',
								    time: 2
								});
						    return false;
						} 

						var thisvar = this;
 
				        $.ajax({
				            url: '/index.php/profile/getsmscode4web',
				            type: 'POST',
				            data:{phonenumber:phone},
				            dataType: 'json',
				            error: function(){
				                  alert('Error '); 
				                  posting = false;
				                 },
				            success: function(result){
 
				                if(result.result==1){
				                	layer.open({
									    content: '获取成功，请保持手机畅通！',
									    className: 'bluelayer',
									    time: 2
									});

			 					// 	var value = {phone:$('.phone_box input').val(),source:2 };
									// if(type == "call"){
									// 	value.call = "1";
									// }else{
									// 	time(this);
									// }
									time(thisvar);

				                }else{
				                	layer.open({
									    content: '请填写正确的手机号',
									    className: 'bluelayer',
									    time: 2
									});

				                } 

				            }

				        });

 
  
						// $.post(rooturl + "/order/getcode", value, function(resp){
						// 	if("false"==(resp.toString())){
					 //            $.common.toast("获取验证码失败!");
					 //  		}else{
					 //            $.common.toast("获取成功,请保持手机畅通!" , 2000);
					 //  		}
						// }); s
					}else{
						//$.common.toast('请在'+wait+'秒后重新获取');
					};
				});

 
			 	$('#loginbtn').bind("click", function(){
			 		 location.href="/index.php/coach/weblogin";
			 	});

			  	//登录
 				$('#regbtn').bind("click", function(){
					var phonenumber = $('#phonenumber').val();
					var checkcode = $('#checkcode').val();
					var realname = $('#realname').val();
					var password = $('#password').val();


					if(phonenumber == "" || phonenumber == undefined){
				         layer.open({
									    content: '请填写电话号码',
									    className: 'bluelayer',
									    time: 2
						 });
						return;
					}

 					if(checkcode == "" || checkcode == undefined){
				         layer.open({
									    content: '请填写验证码',
									    className: 'bluelayer',
									    time: 2
						 });
						return;
					}

 					if(realname == "" || realname == undefined){
				        layer.open({
									    content: '请填写姓名',
									    className: 'bluelayer',
									    time: 2
				    	});
						return;
					}

 					if(password == "" || password == undefined){
				        layer.open({
									    content: '请填写密码',
									    className: 'bluelayer',
									    time: 2
				    	});
						return;
					}



				    $.ajax({
				            url: '/index.php/coach/register_handle',
				            type: 'POST',
				            data:{phonenumber:phonenumber,checkcode:checkcode,realname:realname,password:password},
				            dataType: 'json',
				            error: function(){
				                  alert('Error '); 
				                  posting = false;
				                 },
				            success: function(result){
 
				                if(result.result==1){
				                	layer.open({
									    content: '注册成功!',
									    className: 'bluelayer',
									    time: 2
									});
						         	location.href="/index.php/coach/web_dashboard";
 				                }else if(result.result==3){
				                	layer.open({
									    content: '请填写完整!',
									    className: 'bluelayer',
									    time: 2
									});
 				                }else if(result.result==4){
				                	layer.open({
									    content: '请填写正确手机号!',
									    className: 'bluelayer',
									    time: 2
									});


				                }else{
				                	layer.open({
									    content: '注册失败!',
									    className: 'bluelayer',
									    time: 2
									});
				                } 

				            }

				        });


				});
			});
</script>




<?php 
	include_once("web_footer.php");
?>
